<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<!-- BLOG BAR -->
	<xsl:template match="object[@type='blog']" mode="blog-bar">
		<xsl:param name="id" select="@id" />
		<xsl:param name="alias" select="property[@name='alias']/value" />
		<xsl:param name="rating" select="property[@name='rating']/value" />
		<xsl:param name="allowVote" select="@vote-allow" />
		
		<div class="blog-bar">
			<div class="rating-wrapper">
				<xsl:apply-templates select="document(concat('xmodule://system/getVoted/', $rating, ';', $allowVote, ';', @type-id, ';', @id, ';2'))/data/response/vote" mode="blog-vote" />
			</div>
			
			<div class="avatar">
				<img>
					<xsl:attribute name="alt">
						<xsl:value-of select="property[@name='title']/value" />
					</xsl:attribute>
					<xsl:attribute name="src">
						<xsl:if test="property[@name='avatar']/value = ''">
							<xsl:value-of select="concat ($baseURI, '/images/default-blog-avatar.png')" />
						</xsl:if>
						<xsl:if test="property[@name='avatar']/value != ''">
							<xsl:value-of select="concat ($baseURI, property[@name='avatar']/value)" />
						</xsl:if>
					</xsl:attribute>
				</img>
				
				<i class="corner-mask-white-5 tl"></i>
				<i class="corner-mask-white-5 tr"></i>
				<i class="corner-mask-white-5 br"></i>
				<i class="corner-mask-white-5 bl"></i>
			</div>
			
			<div class="header">
				<div class="controls">
					<xsl:if test="$userGroup != 'guest'">
						<a class="subscribe" id="subscribe_blog" href="#" onclick="Blog.subscribe({@id}); return false;">
							<xsl:if test="@user-member = '1'">
								<xsl:text>покинуть блог</xsl:text>		
							</xsl:if>
							<xsl:if test="@user-member = '0'">
								<xsl:text>вступить в блог</xsl:text>		
							</xsl:if>
						</a>
					</xsl:if>
					<xsl:if test="@admin = '1'">
						<xsl:text> ∙ </xsl:text>
						<a href="{$baseURI}/blogs/edit_blog/{@id}">редактировать</a>
					</xsl:if>
				</div>
				
				<div class="title">
					<a href="{$baseURI}/blog/{$alias}">
						<xsl:value-of select="property[@name='title']/value" />
					</a>
				</div>
				
				<div class="info">
					<a href="#" onclick="Blog.showInfo({@id}); return false;" title="Информация о блоге">
						<img src="{$baseURI}/images/info.png" alt="Информация" />
					</a>
				</div>
			</div>
		</div>
		
		<div id="blog_info" class="blog-info">
			<div class="description">
				<h1>О блоге</h1>
				<xsl:value-of select="property[@name='description']/value" />
			</div>
			
			<div id="blog_members" class="members" />
			
			<i class="corner-f8-10 tl"></i>
			<i class="corner-f8-10 tr"></i>
			<i class="corner-f8-10 br"></i>
			<i class="corner-f8-10 bl"></i>
		</div>
	</xsl:template>
	
	<!-- BLOG VOTE -->
	<xsl:template match="vote" mode="blog-vote">
		<xsl:param name="blogId" select="object_id" />
		<xsl:param name="vote" select="mark" />
		<xsl:param name="allow" select="allow" />
		<xsl:param name="rating" select="rating" />
		<xsl:param name="format" select="format" />
		
		<div class="vote-rating corner" id="blog_rating">
			<a class="minus" title="не нравится" href="#">
				<xsl:choose>
					<xsl:when test="$allow = '0' and $vote = ''">
						<xsl:attribute name="onclick">new Error ('Вы не можете проголосовать'); return false;</xsl:attribute>
						<xsl:attribute name="class">minus cant</xsl:attribute>
					</xsl:when>
					<xsl:when test="$allow = '0' and $vote != ''">
						<xsl:attribute name="onclick">new Error ('Повторное голосование запрещено'); return false;</xsl:attribute>
						<xsl:if test="$vote = '0'">
							<xsl:attribute name="class">minus voted</xsl:attribute>
						</xsl:if>
						<xsl:if test="$vote != '0'">
							<xsl:attribute name="class">minus cant</xsl:attribute>
						</xsl:if>
					</xsl:when>
					<xsl:otherwise>
						<xsl:attribute name="onclick">
							<xsl:value-of select="concat ('Blog.vote (', $blogId, ', 0); return false;')" />
						</xsl:attribute>
					</xsl:otherwise>
				</xsl:choose>
				
				<img src="{$baseURI}/images/post-vote-minus.png" alt="Минус" />
			</a>
			
			<div class="number">
				<xsl:if test="number ($rating) &gt; 0">
					<xsl:attribute name="class">number plus</xsl:attribute>
				</xsl:if>
				<xsl:if test="number ($rating) &lt; 0">
					<xsl:attribute name="class">number minus</xsl:attribute>
				</xsl:if>
				<xsl:value-of select="$format" />
			</div>
			
			<a class="plus" title="нравится" href="#">
				<xsl:choose>
					<xsl:when test="$allow = '0' and $vote = ''">
						<xsl:attribute name="onclick">new Error ('Вы не можете проголосовать'); return false;</xsl:attribute>
						<xsl:attribute name="class">plus cant</xsl:attribute>
					</xsl:when>
					<xsl:when test="$allow = '0' and $vote != ''">
						<xsl:attribute name="onclick">new Error ('Повторное голосование запрещено'); return false;</xsl:attribute>
						<xsl:if test="$vote = '1'">
							<xsl:attribute name="class">plus voted</xsl:attribute>
						</xsl:if>
						<xsl:if test="$vote != '1'">
							<xsl:attribute name="class">plus cant</xsl:attribute>
						</xsl:if>
					</xsl:when>
					<xsl:otherwise>
						<xsl:attribute name="onclick">
							<xsl:value-of select="concat ('Blog.vote (', $blogId, ', 1); return false;')" />
						</xsl:attribute>
					</xsl:otherwise>
				</xsl:choose>
				
				<img src="{$baseURI}/images/post-vote-plus.png" alt="Плюс" />
			</a>
			
			<i class="tl"></i>
			<i class="tr"></i>
			<i class="br"></i>
			<i class="bl"></i>
		</div>
	</xsl:template>

</xsl:stylesheet>